import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import 'dart:io';

class Home extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('cupertino'),
        leading: const Icon(Icons.menu),
        centerTitle: true,
        actions: const [
          Icon(Icons.settings),
        ],
      ),
      body:MyBody(),
    );
  }
}

class MyBody extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // Widget dialogBox;
    // //判断当前的平台信息
    // if (Platform.isIOS) {
    //   //加载iOS风格的组件
    //   dialogBox = CupertinoDemo();
    // }else if (Platform.isAndroid) {
    //   //加载Android风格的组件
    //   dialogBox = MaterialDemo();
    // }
    return Container(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          //安卓风格的组件
          Text('Material - 安卓风格'),
          MaterialDemo(),
          //iOS风格的组件
          Text('Cupertino - ios风格'),
          CupertinoDemo(),
        ],
      ),
    );
  }
}

class MaterialDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints(maxWidth: 300, maxHeight: 200),
      child: AlertDialog(
        title: Text('提示'),
        content: Text('确认删除吗'),
        actions: [
          TextButton(
            child: Text('取消'),
            onPressed: () {
              print('取消的逻辑');
            },
          ),
          TextButton(
            child: Text('确认'),
            onPressed: () {
              print('确认的逻辑');
            },
          ),
        ],
      ),
    );
  }
}

class CupertinoDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Container(
      constraints: BoxConstraints(maxWidth: 300, maxHeight: 200),
      child: CupertinoAlertDialog(
        title: Text('提示'),
        content: Text('确定删除吗'),
        actions: [
          CupertinoDialogAction(
            child: Text('取消'),
            onPressed: () {
              print('取消的逻辑');
            }
          ),
          CupertinoDialogAction(
             child: Text('确认'),
             onPressed: () {
               print('确认的逻辑');
             }
          )
        ],
      )
    );
  }
}

